import { CanLoad, CanActivate, CanActivateChild, Route } from "@angular/router";
import { Observable } from "rxjs/Observable";
import { AuthService } from "../services/auth.service";
import { Injectable } from "@angular/core";

@Injectable()
export class MyAuthGuard implements CanLoad, CanActivate, CanActivateChild {

    constructor(private _authService:AuthService){

    }

    /**
     * 验证模块能否被加载
     * @param route 
     */
    canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
        // return false;
        console.log(JSON.stringify(route, null, 2)); // 查看路由信息
        return true;
    }

    /**
     * 验证路由是否可以激活
     */
    canActivate(){
        //在真实的应用里面需要写一个Service到后端去验证权限
        // return this._authService.canActivate();
        // return false;
        return true;

    }

    /**
     * 验证子路由是否可以激活
     */
    canActivateChild(){
        //在真实的应用里面需要写一个Service到后端去验证权限
        // return true;
        return false;    
    }

}